<?php
declare (strict_types=1);

namespace app\controller;

use app\BaseController;
use app\model\Advise;
use app\model\AdviseClass;

class AdviseController extends BaseController
{
	function class()
	{
		$rows = AdviseClass::order(['weigh'=>'desc'])->select();
		$this->writeJson($rows);
	}
	
	/**
	 * 提建议
	 * @return void
	 */
	function adviseAdd()
	{
		$class_name = $this->request->post('class_name');
		$content = $this->request->post('content');
		$images = $this->request->post('images');
		$name = $this->request->post('name');
		$mobile = $this->request->post('mobile');
		if (empty($class_name)) {
			$this->writeJson(0,'分类填写错误');
		}
		if (empty($content)) {
			$this->writeJson(0,'内容必须填写');
		}
		if (empty($name)) {
			$this->writeJson(0,'姓名必须填写');
		}
		if (empty($mobile)) {
			$this->writeJson(0,'手机号码必须填写');
		}
		$data = [
			'content' => $content,
			'class_name' => $class_name,
			'images' => $images,
			'name' => $name,
			'mobile' => $mobile,
			'user_id' => $this->user_id,
		];
		Advise::create($data);
		$this->writeJson();
	}
}
